package com.tz.online.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**���ڹ�����*/
public class DateUtil {

	/**
	 * ��ݸ�� �ꡢ�¡���������һ�����ڶ���
	 */
	public static Date createDate(int year, int month, int date) {
		Calendar cal = Calendar.getInstance();
		cal.set(year, month - 1, date);
		return cal.getTime();
	}

	/**
	 * ��ʽ������,��ʽ��ģ�����û��Զ���
	 */
	public static String format(Date d, String pattern) {
		String sdate = null;
		if (null != d && null != pattern) {
			sdate = new SimpleDateFormat(pattern).format(d);
		}
		return sdate;
	}

	/**
	 * �����ַ�Ϊ����,��ʽ��ģ�����û��Զ���
	 */
	public static Date parse(String dateStr, String pattern) {
		Date d = null;
		if (null != dateStr && null != pattern) {
			try {
				d = new SimpleDateFormat(pattern).parse(dateStr);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return d;
	}
}
